package cypher;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

import java.io.IOException;
import java.io.UnsupportedEncodingException;

/**
 * Description:
 * Created by 4790K_NSL on 2017/6/12.
 */
public class UtilCypherBase64 {
    public static String encodeInBase64(byte[] bytes){
        BASE64Encoder base64en = new BASE64Encoder();
        return base64en.encode(bytes);
    }

    public static String encodeInBase64(String string) throws UnsupportedEncodingException {
        BASE64Encoder base64en = new BASE64Encoder();
        return base64en.encode(string.getBytes("utf8"));
    }

    public static byte[] decodeInBase64(String base64Code) throws IOException {
        return base64Code==null?null:new  BASE64Decoder().decodeBuffer(base64Code);
    }


}
